/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom;

import java.io.IOException;
import ru.jSkyRoom.bridge.ModBridge;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.support.recoder.DoubleStringRecoder;
import ru.jSkyRoom.support.recoder.DwindleStringRecoder;
import ru.jSkyRoom.support.recoder.OneStringRecoder;
import ru.jSkyRoom.support.recoder.RecoderFacade;
import ru.jSkyRoom.support.recoder.StringRecoder;
import skyproc.Mod;
import skyproc.ModListing;
import skyproc.SPGlobal;
import skyproc.exceptions.BadRecord;

/**
 *
 * @author Rakev
 */
public class JSkyGlobal {

    private static JSkyGlobal instance = new JSkyGlobal();
    private RecoderFacade recoder;

    public static JSkyGlobal getInstance() {
        return instance;
    }

    private JSkyGlobal() {
        recoder = new RecoderFacade(new DwindleStringRecoder());
    }

    public void beginCreatingMod(String author, String newModName) {
        SPGlobal.createGlobalLog();
        ModListing modListing = new ModListing(newModName);
        Mod patch = new Mod(modListing);
        patch.setAuthor(author);
        SPGlobal.setGlobalPatch(patch);
    }

    public void createMod() throws IOException, BadRecord {
        getModExporter().exportMod(getEditingMod());
    }

    public void setPathToData(String path) {
        SPGlobal.pathToData = path;
    }

    public JSkyMod getEditingMod() {
        return new ModBridge(SPGlobal.getGlobalPatch());
    }

    public ModImporter getModImporter() {
        return ModImporter.getInstance();
    }

    public ModExporter getModExporter() {
        return ModExporter.getInstance();
    }
    
    public void setCodePoint(String codePoint){
        StringRecoder stringRecoder = new OneStringRecoder(codePoint);
        recoder = new RecoderFacade(stringRecoder);
    }
    
    public void setCodePoint(String codePoint1, String codePoint2){
        StringRecoder stringRecoder = new DoubleStringRecoder(codePoint1, codePoint2);
        recoder = new RecoderFacade(stringRecoder);
    }

    public RecoderFacade getRecoder() {
        return recoder;
    }
}
